package com.gmcc.aiquality.webadmin.upms.executor;

import cn.hutool.core.collection.CollUtil;
import com.gmcc.aiquality.common.core.object.TokenData;
import com.gmcc.aiquality.common.online.config.OnlineProperties;
import com.gmcc.aiquality.common.online.model.OnlineTable;
import com.gmcc.aiquality.common.online.object.BaseOnlineExtendExecutor;
import com.gmcc.aiquality.common.online.util.OnlineDataSourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class ProjectExtendExampleExecutor extends BaseOnlineExtendExecutor {
    @Autowired
    private OnlineProperties onlineProperties;

    @Autowired
    private OnlineDataSourceUtil onlineDataSourceUtil;

    @Override
    public void afterSelectList(OnlineTable table, List<Map<String, Object>> resultList) {
        String tableName = table.getTableName();
        //得到当前用户的基础信息
        TokenData tokenData = TokenData.takeFromRequest();
        Boolean isAdmin = tokenData.getIsAdmin();
        Long userId = tokenData.getUserId();
        String loginName = tokenData.getLoginName();
        Long deptId = tokenData.getDeptId();
        String deptName = tokenData.getDeptName();
        Integer userStatus = tokenData.getUserStatus();
        String  dataPermId= tokenData.getDataPermId();
        if ((tableName !=null && tableName.equals("project"))){
            for (Map<String, Object> map : resultList) {
                map.put("loginName",loginName);
                map.put("deptName",deptName);
                map.put("isAdmin",isAdmin);
                map.put("userId",userId);
                map.put("deptId",deptId);
                map.put("userStatus",userStatus);
                map.put("dataPermId",dataPermId);
            }
        }
    }
}
